"""
任务过程飞行器事件对象

date: 2025/7/17
author: SiHeng Tang
file: mission_mav_events.py
copyright(c) DFSA Eastern Software
此程序不能提供任何担保 WITHOUT WARRANTY OF ANY KIND
"""

from mj_errors import MJRuntimeError


class MavError(MJRuntimeError):
    def __init__(self, code: int):
        super().__init__(MJRuntimeError.PROCESSOR_ERROR, "mav mission flight exception")
        self.mav_error_code = code


class MavEvents:
    MAV_POWER_ON = -1
    MAV_POWER_ON_STRING = "mav power on"
    MAV_GPS_HOMED = 0
    MAV_GPS_HOMED_STRING = "mav gps home gained"
    MAV_ARMED_THROTTLE = 1
    MAV_ARMED_THROTTLE_STRING = "mav has been armed"
    MAV_FINISH_TAKEOFF = 2
    MAV_FINISH_TAKEOFF_STRING = "mav takeoff finished"
    MAV_REACH_WP_TRANS = 3
    MAV_REACH_WP_TRANS_STRING = "mav reached waypoint trans to insight mode"
    MAV_GET_TARGET_POSITION = 4
    MAV_GET_TARGET_POSITION_STRING = "mav got target position"
    MAV_RELEASE_PAYLOAD = 5
    MAV_RELEASE_PAYLOAD_STRING = "released payload"
    MAV_DISARM_THROTTLE = 6
    MAV_DISARM_THROTTLE_STRING = "landing complete"
    MAV_MANUAL_INTERP = 7
    MAV_MANUAL_INTERP_STRING = "manual interrupter mission serial"
    MAV_POSITION_DOWN = 8
    MAV_POSITION_DOWN_STRING = "mav completed positioning for attack"
    MAV_WAIT_TIMEOUT = 9
    MAV_WAIT_TIMEOUT_STRING = "mav seems be forgotten"
    string_dict = {
        MAV_POWER_ON: MAV_POWER_ON_STRING,
        MAV_GPS_HOMED: MAV_GPS_HOMED_STRING,
        MAV_ARMED_THROTTLE: MAV_ARMED_THROTTLE_STRING,
        MAV_FINISH_TAKEOFF: MAV_FINISH_TAKEOFF_STRING,
        MAV_REACH_WP_TRANS: MAV_REACH_WP_TRANS_STRING,
        MAV_GET_TARGET_POSITION: MAV_GET_TARGET_POSITION_STRING,
        MAV_RELEASE_PAYLOAD: MAV_RELEASE_PAYLOAD_STRING,
        MAV_DISARM_THROTTLE: MAV_DISARM_THROTTLE_STRING,
        MAV_MANUAL_INTERP: MAV_MANUAL_INTERP_STRING,
        MAV_WAIT_TIMEOUT: MAV_WAIT_TIMEOUT_STRING,
        MAV_POSITION_DOWN: MAV_POSITION_DOWN_STRING
    }


class MavStatus:
    # 此状态解决上电第一次初始化问题，系统不会报告从一个转态切换到同样的状态异常
    MJ_SYSTEM_INITIAL = -1
    MJ_SYSTEM_INITIAL_STRING = "controller initialize"
    PLANE_INITIALIZE = 0
    PLANE_INITIALIZE_STRING = "plane initializing"
    READY = 1
    READY_STRING = "ready for mission"
    TAKEOFF = 2
    TAKEOFF_STRING = "plane takeoff"
    WORK_WAY = 3
    WORK_WAY_STRING = "plane coming in hot"
    INSIGHT = 4
    INSIGHT_STRING = "plane searching"
    ATTACK = 5
    ATTACK_STRING = "plane going to attack"
    BACK_HOME = 6
    BACK_HOME_STRING = "plane backing home"
    RESCUE = 7
    RESCUE_STRING = "plane in rescue mode"
    POSITIONING = 8
    POSITIONING_STRING = "positioning carry aircraft for attack line"
    WAIT_TIMEOUT = 9
    WAIT_TIMEOUT_STRING = "waiting for target timeout, auto select target and attack"
    string_dict = {
        MJ_SYSTEM_INITIAL: MJ_SYSTEM_INITIAL_STRING,
        PLANE_INITIALIZE: PLANE_INITIALIZE_STRING,
        READY: READY_STRING,
        TAKEOFF: TAKEOFF_STRING,
        WORK_WAY: WORK_WAY_STRING,
        INSIGHT: INSIGHT_STRING,
        ATTACK: ATTACK_STRING,
        BACK_HOME: BACK_HOME_STRING,
        RESCUE: RESCUE_STRING,
        POSITIONING: POSITIONING_STRING,
        WAIT_TIMEOUT: WAIT_TIMEOUT_STRING
    }
